package com.qiyu.tech.web.starter;

import com.qiyu.mall.user.interfaces.dto.WorkerDTO;

/**
 * 寄存memberId的工具
 *
 * @author linhao
 * @date 2019/8/28
 * @Version V1.0
 */
public class SecurityContextHolder {

    private static final ThreadLocal<Integer> contextHolder=new ThreadLocal<>();
    private static final ThreadLocal<String> tokenHolder=new ThreadLocal<>();
    private static final ThreadLocal<WorkerDTO> workerHolder=new ThreadLocal<>();



    public static void clearContext(){
        tokenHolder.remove();
        contextHolder.remove();
        workerHolder.remove();
    }

    public static WorkerDTO getCurrentWorker(){
        return workerHolder.get();
    }

    public static void setCurrentWorker(WorkerDTO worker){
        if(worker!=null){
            workerHolder.set(worker);
        }
    }


    public static Integer getCurrentUser(){
        return contextHolder.get();
    }

    public static String getToken(){
        return tokenHolder.get();
    }

    public static void setTokenHolder(String token){
        if(token!=null){
            tokenHolder.set(token);
        }
    }

    public static void setCurrentUser(Integer context){
        if(context!=null){
            contextHolder.set(context);
        }
    }

}
